﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a training used for the classifier.</summary>
	// Token: 0x0200003A RID: 58
	public class HFeatureSet : HHandle
	{
		// Token: 0x06000549 RID: 1353 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HFeatureSet() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x0600054A RID: 1354 RVA: 0x0001EA28 File Offset: 0x0001CC28
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HFeatureSet(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x0600054B RID: 1355 RVA: 0x0001EA37 File Offset: 0x0001CC37
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HFeatureSet(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x0600054C RID: 1356 RVA: 0x0001EA46 File Offset: 0x0001CC46
		private void AssertSemType()
		{
			base.AssertSemType("feature_set");
		}

		// Token: 0x0600054D RID: 1357 RVA: 0x0001EA53 File Offset: 0x0001CC53
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HFeatureSet obj)
		{
			obj = new HFeatureSet(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x0600054E RID: 1358 RVA: 0x0001EA6C File Offset: 0x0001CC6C
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HFeatureSet[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HFeatureSet[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HFeatureSet(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Read a training data set from a file.
		///   Modified instance represents: Identification of the data set to train.
		/// </summary>
		/// <param name="fileName">Filename of the data set to train. Default: "sampset1"</param>
		// Token: 0x0600054F RID: 1359 RVA: 0x0001EADC File Offset: 0x0001CCDC
		public HFeatureSet(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(1888);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Read a training data set from a file.
		///   Modified instance represents: Identification of the data set to train.
		/// </summary>
		/// <param name="fileName">Filename of the data set to train. Default: "sampset1"</param>
		// Token: 0x06000550 RID: 1360 RVA: 0x0001EB28 File Offset: 0x0001CD28
		public void ReadSampset(string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(1888);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Train the classifier with one data set.
		///   Instance represents: Number of the data set to train.
		/// </summary>
		/// <param name="classifHandle">Handle of the classifier.</param>
		/// <param name="outfile">Name of the protocol file. Default: "training_prot"</param>
		/// <param name="NSamples">Number of arrays of attributes to learn. Default: 500</param>
		/// <param name="stopError">Classification error for termination. Default: 0.05</param>
		/// <param name="errorN">Error during the assignment. Default: 100</param>
		// Token: 0x06000551 RID: 1361 RVA: 0x0001EB74 File Offset: 0x0001CD74
		public void LearnSampsetBox(HClassBox classifHandle, string outfile, int NSamples, double stopError, int errorN)
		{
			IntPtr proc = HalconAPI.PreCall(1890);
			base.Store(proc, 1);
			HalconAPI.Store(proc, 0, classifHandle);
			HalconAPI.StoreS(proc, 2, outfile);
			HalconAPI.StoreI(proc, 3, NSamples);
			HalconAPI.StoreD(proc, 4, stopError);
			HalconAPI.StoreI(proc, 5, errorN);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(classifHandle);
		}

		/// <summary>
		///   Free memory of a data set.
		///   Instance represents: Number of the data set.
		/// </summary>
		// Token: 0x06000552 RID: 1362 RVA: 0x0001EBD8 File Offset: 0x0001CDD8
		public void ClearSampset()
		{
			IntPtr proc = HalconAPI.PreCall(1893);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Classify a set of arrays.
		///   Instance represents: Key of the test data.
		/// </summary>
		/// <param name="classifHandle">Handle of the classifier.</param>
		/// <returns>Error during the assignment.</returns>
		// Token: 0x06000553 RID: 1363 RVA: 0x0001EC0C File Offset: 0x0001CE0C
		public double TestSampsetBox(HClassBox classifHandle)
		{
			IntPtr proc = HalconAPI.PreCall(1897);
			base.Store(proc, 1);
			HalconAPI.Store(proc, 0, classifHandle);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			double result;
			num = HalconAPI.LoadD(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(classifHandle);
			return result;
		}
	}
}
